<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
用户名： <input type="text" name="" class="userName"> 
密码： <input type="text" name="" class="passWord">
<button>登录</button>
<script type="text/javascript">
	let btn = document.querySelector('button')
	let userName = document.querySelector('.userName')
	let passWord = document.querySelector('.passWord')
	btn.onclick = function() {
		//1.application/x-www-form-urlencoded
		let xhr = new XMLHttpRequest()
		//2.连接服务 post请求不能拼接参数
		xhr.open('post',"http://wish.byesame.com/login")
		//请求头  前固定后问端
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
		//3.发送数据
		xhr.send(`userName=${userName.value}&passWord=${passWord.value}`)
		//4.接受数据
		xhr.onreadystatechange = function() {
			if(xhr.readyState == 4){
				let res = JSON.parse(xhr.responseText)
				console.log(res)
				//将token存储到本地 localStorage.setItem('属性名','属性值')
				if(res.code == 200){
					localStorage.setItem('token',res.data.token)
					//跳转地址
					location.href = './04登录token.html'
				}
			}
		}


	}
</script>
</body>
</html>